home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3801 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  52 lines

  1. Path: lasernet.com!jonathan_wooldridge
  2. Newsgroups: comp.lang.c
  3. Message-ID: <60131010101$71C7@lasernet.com>
  4. X-Gateway: Act-Up 4.6  31 Jan 96 01:01:01  LaserNet
  5. Date: Tue, 30 Jan 96 23:36:34 LOC
  6. Organization: 1BBS ■ Imperial Beach CA ■ 619∙429∙6521/6123 ■ (52:1000/153)
  7. From: Jonathan Wooldridge <jonathan_wooldridge@lasernet.com>
  8. Subject: Plasma
  9.  
  10. Greetings!
  11.     I'm trying to create a plasma field, using a recursive algorithm.
  12.  
  13. /*\
  14. |*| Given four point rectangle
  15. |*| fill with random gradiant colors
  16. \*/
  17. void plasma(int x1, int y1, int x2, int y2, int TotalColor, int depth){
  18.  
  19.     TotalColor  ????    // don't know what to put here.
  20.  
  21.     int midx = (x1+x2)/2; // used for subdividing the rectangle
  22.     int midy = (y1+y2)/2;
  23.  
  24.     if(depth--){ // reduce depth each pass, done on 0
  25.         plasma(x1,y1, midx,midy, TotalColor, depth);  // upper left quadrant
  26.         plasma(midx,y1, x2,midy, TotalColor, depth);  // upper right quadrant
  27.         plasma(x1,midy, midx,y2, TotalColor, depth);  // lower left quadrant
  28.         plasma(midx,midy x2,y2, TotalColor, depth);   // lower right quadrant
  29.     }
  30.     else{ // maximum depth reached; fill in remaining area.
  31.         drwfillbox(SET, x1,y1, x2,y2, TotalColor);
  32.     };
  33. };
  34.  
  35. Anyway, you get the general idea. Point is, I'm not sure how to go about
  36.     changing the color value, so that it is the average value of the
  37.     outer ones, modified by some random.
  38.  
  39. I've tried TotalColor += (random(255)+1)/level where level is the
  40.     final depth, but this gives a rather cubic looking field. Pretty tho.
  41.     Anyway, I'm trying to achieve a smooth gradient.
  42.  
  43. Note that I could also have put the draw routine as four pixels, in
  44.     each pass, and then test for adjacent pixels, to bail the loop.
  45.     Any suggestions on approach?
  46.  
  47.                  -SpyroGyra
  48. ---
  49.  ■ TLX v4.00 ■ Compile, run, curse...  Recompile, rerun, recurse...
  50.  
  51. ---
  52.